package sskj.regulatory.di.module

import android.support.v4.app.FragmentManager
import android.support.v7.app.AppCompatActivity
import android.view.LayoutInflater
import dagger.Module
import dagger.Provides
import io.armcha.ribble.domain.repository.SiteVideoRepository
import sskj.regulatory.data.cache.MemoryCache
import sskj.regulatory.data.mapper.Mapper
import sskj.regulatory.data.network.SiteVideoApiService
import sskj.regulatory.data.repository.SiteVideoDataRepository
import sskj.regulatory.di.scope.PerActivity
import sskj.regulatory.data.network.AuthApiService
import sskj.regulatory.data.network.UserApiService
import sskj.regulatory.data.pref.Preferences
import sskj.regulatory.data.repository.UserDataRepository
import sskj.regulatory.domain.repository.UserRepository


@Module
class ActivityModule(private val activity: AppCompatActivity) {

    @PerActivity
    @Provides
    fun providesActivity(): AppCompatActivity = activity

    @PerActivity
    @Provides
    fun providesLayoutInflater(activity: AppCompatActivity): LayoutInflater =
            LayoutInflater.from(activity)

    @PerActivity
    @Provides
    fun providesFragmentManager(activity: AppCompatActivity): FragmentManager =
            activity.supportFragmentManager


    @PerActivity
    @Provides
    fun provideSiteVideoRepository(siteVideoApiService: SiteVideoApiService,
                                   memoryCache: MemoryCache,
                                   mapper: Mapper): SiteVideoRepository = SiteVideoDataRepository(siteVideoApiService, memoryCache, mapper)

    @PerActivity
    @Provides
    fun provideUserRepository(authApiService: AuthApiService,
                              userApiService: UserApiService,
                              preferences: Preferences,
                              memoryCache: MemoryCache,
                              mapper: Mapper): UserRepository = UserDataRepository(authApiService, userApiService, preferences, memoryCache, mapper)

}